package ustc.xiaoyang.karl.linkedlist;

/**
 * 26.两两交换链表中的节点
 */
public class ExchangeNodes26 {
    public static void main(String[] args) {

    }
    public static ListNode swapPairs(ListNode head) {
        ListNode dummy = new ListNode(0,head);
        ListNode cur = dummy;
        while(cur.next != null && cur.next.next != null){
            ListNode p = cur.next;
            ListNode q = cur.next.next;
            cur.next = q;
            p.next = q.next;
            q.next = p;
            cur = p;
        }
        return dummy.next;
    }
}
